document.querySelector('#btn-login').addEventListener('click',async function(e){
    e.preventDefault()
    const form = document.querySelector('.login-form')
    const formdata = serialize(form,{hash:true,empty:true})
    // console.log(formdata)
    let unamestr = /^[a-zA-Z0-9]{8,30}$/
    let passwordstr = /^[a-zA-Z0-9]{6,30}$/
    if(unamestr.test(formdata.username) && passwordstr.test(formdata.password)){
        axios({
            url:'/login',
            method:'POST',
            data:formdata
        }).then(res=>{
            console.log(res)
            pxmu.success('登录成功')
            localStorage.setItem('uname',res.data.data.username)
            localStorage.setItem('token',res.data.data.token)
            location.href = './index.html'
            
        }).catch(err=>{
            alert('用户名或密码错误')
        })
    }else{
        alert('用户名或密码格式错误')
    }
})
